package com.ysd.controller;

import com.ysd.entity.User;
import com.ysd.service.UserService;
import com.ysd.utils.TokenUtil;
import org.aspectj.weaver.patterns.IToken;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * @ClassName UserController
 * @Description TODO
 * @Author lvzhenzhen
 * @Date 2021/11/22 16:54
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Resource
    UserService userService;

    @RequestMapping(value = "/login", produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String login(@RequestParam String username, @RequestParam String pwd){
        User user = userService.login(username,pwd);
        System.out.println(user);
        if (user!=null){
            String token = TokenUtil.token(username,pwd);
            return token;
        }
        return "登录失败";
    }
}
